From 1b55f62024b1ee1de1e9fb576e6fb8a72155c174 Mon Sep 17 00:00:00 2001 From: justbur Date: Tue, 14 Jul 2015 09:26:52 -0400 Subject: [PATCH] Cleanup replacement functions again --- which-key.el | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/which-key.el b/which-key.el index 19528b82bf2..a3ec4f2e15e 100644 --- a/which-key.el +++ b/which-key.el @@ -273,16 +273,13 @@ bottom." "Internal function to add (KEY . REPL) to ALIST." (when (or (not (stringp key)) (not (stringp repl))) (error "KEY and REPL should be strings")) - (if alist - (progn - (if (assoc-string key alist) - (progn - (message "which-key note: The key %s already exists in %s. This addition will override that replacement." - key alist) - (setcdr (assoc-string key alist) repl)) - (push (cons key repl) alist))) - (setq alist (list (cons key repl)))) - alist) + (cond ((null alist) (list (cons key repl))) + ((assoc-string key alist) + (message "which-key note: The key %s already exists in %s. This addition will override that replacement." + key alist) + (setcdr (assoc-string key alist) repl) + alist) + (t (cons (cons key repl) alist)))) ;;;###autoload (defun which-key/add-key-based-replacements (key repl &rest more) @@ -308,9 +305,7 @@ pairs) will only apply when the major-mode MODE is active." (error "MODE should be a symbol corresponding to a value of major-mode")) (let ((mode-alist (cdr (assq mode which-key-key-based-description-replacement-alist)))) (while key - (if mode-alist - (setq mode-alist (which-key//add-key-based-replacements mode-alist key repl)) - (setq mode-alist (list (cons key repl)))) + (setq mode-alist (which-key//add-key-based-replacements mode-alist key repl)) (setq key (pop more) repl (pop more))) (if (assq mode which-key-key-based-description-replacement-alist) (setcdr (assq mode which-key-key-based-description-replacement-alist) mode-alist) -- 2.30.2